<p>
Messages sent from the world into Nuntium and then into your application are called Application Terminated messages. <a href="http://code.google.com/p/nuntium/wiki/Messages#Application_Terminated_messages" target="_blank">Learn more...</a>
</p>

<form id="at_messages_form" action="#at">
<input type="hidden" name="page" value="<%= @page -%>" />
<input type="hidden" name="previous_search" value="<%= @search -%>" />
<input type="hidden" id="at_all" name="at_all" value="0" />

<%- if channels.incoming.empty? -%>
  <p>
  Create an incoming or bidirectional Channel to create AT Messages:
  <%= render 'shared/create_channel' -%>
  </p>
<%- else -%>
  <%= link_to '<img src="/images/new_message.png" width="16" height="16" style="position:relative; top:4px" alt="Create new AT Message">Create new AT Message'.html_safe, new_at_message_path -%> &nbsp; &nbsp;
<%- end -%>
Search: <input type="text" name="search" value="<%= @search.try(:html_safe) -%>" size= "50" class="<%= @search.present? ? 'highlighted' : '' -%>"/> <a href="http://code.google.com/p/nuntium/wiki/AdvancedSearch" target="_blank" title="You can filter by field like 'id:5', 'before:&quot;20 minutes ago&quot;', 'state:queued', etc.">?</a> &nbsp; &nbsp;
Select: <%= link_to_function 'all', 'select_all_at_messages()' -%>, <%= link_to_function 'none', 'select_none_at_messages()' -%> &nbsp; &nbsp;
Actions: <%= link_to_function 'mark as cancelled', 'mark_at_messages_as_cancelled()' -%>

<div><%= page_entries_info @at_messages, :entry_name => 'message' -%></div>
<%= will_paginate @at_messages, :param_name => 'page', :params => { :previous_search => @search } -%>

<div id="all_at_messages_text" style="display:none"></div>

<%- if @at_messages.present? -%>
  <table border="1" class="table">
    <tr>
      <th></th>
      <th>When</th>
      <th>Id</th>
      <th>Guid</th>
      <th>Channel Relative Id</th>
      <th>From</th>
      <th>To</th>
      <th>Subject</th>
      <th>Body</th>
      <th>Channel</th>
      <th>Application</th>
      <th>Tries</th>
      <th>State</th>
      <th></th>
    </tr>
    <tr>
    <%- @at_messages.each_with_index do |msg, i| -%>
      <tr class="<%= i.even_to_s -%>">
        <td><input type="checkbox" name="at_messages[]" value="<%= msg.id -%>" <%= 'checked="checked"' if !params[:at_messages].nil? && params[:at_messages].include?(msg.id.to_s) -%>/></td>
        <td><%= time_ago msg.timestamp -%></td>
        <td align="right"><%= msg.id -%></td>
        <td><%= short_html msg.guid -%></td>
        <td><%= short_html msg.channel_relative_id -%></td>
        <td><%= link_to msg.from, thread_at_message_path(msg), :target => '_blank' if msg.from.present? -%></td>
        <td><%= msg.to -%></td>
        <td><%= short_html message_subject(msg) -%></td>
        <td><%= short_html message_body(msg) -%></td>
        <td><%= msg.channel.try(:name) -%></td>
        <td><%= msg.application.try(:name) -%></td>
        <td align="right"><%= msg.tries -%></td>
        <td><%= msg.state -%></td>
        <td><%= link_to 'view log', msg, :target => '_blank'%></td>
      </tr>
    <%- end -%>
  </table>
<%- end -%>

<%= will_paginate @at_messages, :param_name => 'page', :params => { :page => @search } -%>
</form>

<script>
var total_at_messages = <%= @at_messages.total_entries -%>;
var current_at_messages = <%= @at_messages.length -%>;
<%-
if !params[:at_all].nil? && params[:at_all].to_b
  -%>
  select_all_pages_at_messages();
  <%-
end
-%>
</script>
